//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.MemberContractDao;
import com.aidong.model.wills.ContractInfo;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"giftCardQuery"})
public class GiftCardQueryController extends BaseController {
    @Resource
    MemberContractDao memberContractDao;

    public GiftCardQueryController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return (new ModelAndView("member/giftcardquery/list")).addObject("dt1", sdf.format(new Date(System.currentTimeMillis() - 86400000L))).addObject("dt2", sdf.format(new Date()));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "cardCode",required = false) String cardCode, @RequestParam(value = "contractCode",required = false) String contractCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "c.shopCode", shopCode);
        cd.eq("m.cardCode", cardCode);
        cd.eq("c.contractCode", contractCode);
        if(!this.chkNull(dateFrom)) {
            cd.ge("c.saleDate", this.getDateFrom(dateFrom));
        }

        if(!this.chkNull(dateTo)) {
            cd.le("c.saleDate", this.getDateTo(dateTo));
        }

        cd.addSqlw("c.giftCardType<>\'\'", new Object[0]);
        this.memberContractDao.queryPageList(pg, cd);
        ModelAndView mv = new ModelAndView("member/giftcardquery/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "cardCode",required = false) String cardCode, @RequestParam(value = "contractCode",required = false) String contractCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, '\uea60');
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "c.shopCode", shopCode);
            cd.eq("m.cardCode", cardCode);
            cd.eq("c.contractCode", contractCode);
            if(!this.chkNull(dateFrom)) {
                cd.ge("c.saleDate", this.getDateFrom(dateFrom));
            }

            if(!this.chkNull(dateTo)) {
                cd.le("c.saleDate", this.getDateTo(dateTo));
            }

            cd.addSqlw("c.giftCardType<>\'\'", new Object[0]);
            this.memberContractDao.queryPageList(e, cd);
            ExportXls xls = new ExportXls(response, "赠送储值卡流水", "赠送储值卡流水");
            xls.addHead(new String[]{"门店编号", "门店名称", "合同号", "卡号", "会员号", "会员姓名", "销售日期", "会籍类型", "合同开始日期", "合同结束日期", "储值卡类型", "储值卡号", "储值卡金额", "销售员", "销售员2", "操作员"});
            xls.setWidth(new int[]{10, 15, 15, 12, 20, 10, 20, 20, 12, 12, 15, 20, 10, 15, 15, 15});
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                ContractInfo contract = (ContractInfo)i$.next();
                xls.addRow(new Object[]{contract.getShopCode(), this.cache.getValue("shopName", contract.getShopCode()), contract.getContractCode(), contract.getCardCode(), contract.getMemberCode(), contract.getMemberName(), sdf2.format(contract.getSaleDate()), contract.getCardType() + " - " + this.cache.getValue("cardType", contract.getCardType()), sdf.format(contract.getBeginTime()), sdf.format(contract.getEndTime()), this.cache.getValue("giftCardType", contract.getGiftCardType()), contract.getGiftCardCode(), contract.getGiftCardAmount(), this.nvl(contract.getSalesCode()) + " - " + this.nvl(this.cache.getValue("salesName", contract.getSalesCode())), this.nvl(contract.getSalesCode2()) + " - " + this.nvl(this.cache.getValue("salesName", contract.getSalesCode2())), this.nvl(contract.getCreateUser()) + " - " + this.nvl(this.cache.getValue("userName", contract.getCreateUser()))});
            }

            xls.close();
            this.addUserLog("导出赠送储值卡流水查询", e.getResultList().size() + "条记录");
        } catch (Exception var14) {
            this.log.error("import", var14);
        }

        return null;
    }
}
